*** Tables (2024-12-17)

use data_REP_20241217.dta, clear

drop if missing(prop)
drop if Last=="vacant"

egen propno = group(prop)
destring propno, replace
gen propch = propno
replace propch = propno + (0.1)*(Chamber=="Senate")
egen propchno = group(propch)

* Issure orientation (1=roll call, 2=ref vote, 3=sponsor)
gen issuevalid1 = (issuescore1==1) | (issuescore1==-1)
gen issuevalid2 = (issuescore2==1) | (issuescore2==-1)
gen issuevalid3 = (issuescore3==1) | (issuescore3==-1)

* Salience
gen sal = 1 if salience=="Low"
replace sal = 2 if salience=="Medium"
replace  sal = 3 if salience=="High"

* Repealed laws
gen repeal = 0
replace repeal=1 if (prop=="AK_2000_M6" | prop=="CA_2000_P30" | prop=="CA_2000_P31" | ///
  prop=="CA_2004_P72" | prop=="CA_2014_P48" | prop=="CA_2020_P25" | ///
  prop=="ME_2008_Q1" | prop=="MI_2006_0603" | ///
  prop=="ND_2016_RM1" | prop=="OH_2011_I2" | prop=="SD_2016_RL19" | prop=="SD_2016_RL20" | ///
  prop=="WA_2002_R53" | prop=="WA_2004_R55" | prop=="WA_2019_R88")
  
* General election
gen general=1
replace general=0 if (prop=="CA_2000_P29" | prop=="CA_2000_P30" | prop=="CA_2000_P31" | ///
  prop=="CA_2008_P94" | prop=="CA_2008_P95" | prop=="CA_2008_P96" | prop=="CA_2008_P97" | ///
  prop=="CO_2020_P113" | prop=="ND_2012_RM4" | prop=="ND_2016_RM1")
    
* District referendum returns
gen yespct = Yes/(Yes+No)
gen yes50 = max(yespct,1-yespct)
gen Votes=Demvote+Repvote
gen districtyes = (Yes>No) if ~missing(Yes) & ~missing(No)

* Roll call votes
gen rollvalid = (Vote=="Yes" | Vote=="No")
gen rollyes = 1 if Vote=="Yes" & rollvalid==1
replace rollyes = 0 if Vote=="No" & rollvalid==1
gen rollno = 1-rollyes if ~missing(Vote)

* Congruence
gen cong = (Vote=="Yes" & yespct>.5) | (Vote=="No" & yespct<.5) if rollvalid~=0

* Legislative district competitiveness
gen closeness = abs((Demvote-Repvote)/(Demvote+Repvote))
gen unopposed = (closeness==1)

* Green CA 2000 P30, P31 (Bock). Ind CA 2000 P29 (Kopp)
* Party control (AK=Rep, CA=Dem, CO=Dem, ME=Dem, MD=Dem, MI=Rep, ND=Rep, SD=Rep, WA=Dem except Senate 2003-2004 )
gen partycontrol = "Dem"
replace partycontrol = "Rep" if (state=="AK") | (state=="MI") | (state=="ND") | ///
 (state=="OH") | (state=="SD") | (state=="WA" & Chamber=="Senate" & year==2004)
gen party = 1 if Party=="Rep"
replace party = -1 if Party=="Dem" | Party=="Green" | (Party=="Ind" & state=="ME")
replace party = . if Party=="Ind" & state=="CA"
* CA independent Quentin Kopp did not caucus with either party. Originally Dem.
gen gop = 1 if party==1
replace gop = 0 if party==-1
gen majgop = (partycontrol=="Rep")
gen rollyesR = (rollyes==1)&(gop==1)
gen rollyesD = (rollyes==1)&(gop==0)
gen rollnoR = (rollno==1)&(gop==1)
gen rollnoD = (rollno==1)&(gop==0)

* Other variables
gen senate = (Chamber=="Senate")

* Ideology (ideotype=1 conservative, ideotype=-1 liberal)
gen ideo = np_score
gen ideoabs = abs(ideo)
gen ideotype=-1 if ~missing(ideo)
replace ideotype=1 if ideo>0 & ~missing(ideo)
gen ideoyes1 = 0 if ~missing(ideo) & issuevalid1==1
replace ideoyes1 = 1 if ((ideo>0 & issuescore1==1) | (ideo<0 & issuescore1==-1)) & ~missing(ideo) & issuevalid1==1
gen ideoyes2 = 0 if ~missing(ideo) & issuevalid2==1
replace ideoyes2 = 1 if ((ideo>0 & issuescore2==1) | (ideo<0 & issuescore2==-1)) & ~missing(ideo) & issuevalid2==1
gen ideoyes3 = 0 if ~missing(ideo) & issuevalid3==1
replace ideoyes3 = 1 if ((ideo>0 & issuescore3==1) | (ideo<0 & issuescore3==-1)) & ~missing(ideo) & issuevalid3==1

gen iyes1 = ideo*issuescore1 if issuevalid1==1
gen iyes2 = ideo*issuescore2 if issuevalid2==1
gen iyes3 = ideo*issuescore3 if issuevalid3==1

 
* District orientation on issue (-1 is liberal, +1 is conservative)
gen districtview1 = -1 if ((yespct<.5 & issuescore1==1) | (yespct>.5 & issuescore1==-1)) & issuevalid1==1
replace districtview1 = 1 if ((yespct>.5 & issuescore1==1)|(yespct<.5 & issuescore1==-1)) & issuevalid1==1
gen districtview2 = -1 if ((yespct<.5 & issuescore2==1) | (yespct>.5 & issuescore2==-1)) & issuevalid2==1
replace districtview2 = 1 if ((yespct>.5 & issuescore2==1)|(yespct<.5 & issuescore2==-1)) & issuevalid2==1
gen districtview3 = -1 if ((yespct<.5 & issuescore3==1) | (yespct>.5 & issuescore3==-1)) & issuevalid3==1
replace districtview3 = 1 if ((yespct>.5 & issuescore3==1)|(yespct<.5 & issuescore3==-1)) & issuevalid3==1


* DISAGREE: Ideology and district view
gen DISAGREE1 = (ideotype~=districtview1) if issuevalid1==1 & ~missing(ideo) & rollvalid==1
gen DISAGREE2 = (ideotype~=districtview2) if issuevalid2==1 & ~missing(ideo) & rollvalid==1
gen DISAGREE3 = (ideotype~=districtview3) if issuevalid3==1 & ~missing(ideo) & rollvalid==1
gen DISAGREEp = (party~=districtview1)  if issuevalid1==1 & ~missing(party) & rollvalid==1
gen AGREE1 = (ideotype==districtview1) if issuevalid1==1 & ~missing(ideo)
gen AGREE2 = (ideotype==districtview2) if issuevalid2==1 & ~missing(ideo)
gen AGREE3 = (ideotype==districtview3) if issuevalid3==1 & ~missing(ideo)

* Term limits
gen termstate = (state=="CA" | state=="CO" | state=="ME" | state=="MI" | state=="OH" | state=="SD") 
gen termlim = (Term-yearroll)
gen lastterm = 0 if termstate==1
replace lastterm = 1 if (state=="CA" & termlim<2 & Chamber=="House")
replace lastterm = 1 if (state=="CA" & termlim<4 & Chamber=="Senate")
replace lastterm = 1 if (state=="CO" & termlim<2 & Chamber=="House")
replace lastterm = 1 if (state=="CI" & termlim<4 & Chamber=="Senate")
replace lastterm = 1 if (state=="ME" & termlim<2)
replace lastterm = 1 if (state=="MI" & termlim<2 & Chamber=="House")
replace lastterm = 1 if (state=="MI" & termlim<4 & Chamber=="Senate")
replace lastterm = 1 if (state=="OH" & Chamber=="Senate" & termlim<4 )
replace lastterm = 1 if (state=="OH" & Chamber=="House" & termlim<2)
replace lastterm = 1 if (state=="SD" & termlim<2)
gen lasttermfull = lastterm
replace lasttermfull = 0 if missing(lastterm)
gen DISAGREE1_lastterm = DISAGREE1*lastterm
gen AGREE1_lastterm = AGREE1*lastterm
gen DISAGREE1_lasttermfull = DISAGREE1*lasttermfull
gen AGREE1_lasttermfull = AGREE1*lasttermfull
gen DISAGREE1_termstate = DISAGREE1*termstate


* District agreement based on presidential vote
gen ideodistmissing = missing(DemPres) | missing(RepPres)
gen ideodist = 1 if DemPres<RepPres & ideodistmissing==0
replace ideodist = -1 if DemPres>RepPres & ideodistmissing==0
gen DISAGREEdist1 = (ideodist~=districtview1) if issuevalid1==1 & ideodistmissing==0
gen DISAGREEdist2 = (ideodist~=districtview2) if issuevalid2==1 & ideodistmissing==0
gen DISAGREEdist3 = (ideodist~=districtview3) if issuevalid3==1 & ideodistmissing==0
gen AGREEdist1 = (DISAGREEdist1==0) if issuevalid1==1 & ideodistmissing==0
gen AGREEdist2 = (DISAGREEdist2==0) if issuevalid2==1 & ideodistmissing==0
gen AGREEdist3 = (DISAGREEdist3==0) if issuevalid3==1 & ideodistmissing==0


* Legislator and district ideology agreement
gen AGREElegdist = (ideodist==ideotype) if ~missing(ideo) & ideodistmissing==0

gen iXd1 = ideoyes1*districtyes
gen iXd2 = ideoyes2*districtyes
gen iXd3 = ideoyes3*districtyes
gen iXyespct1 = ideoyes1*yespct
gen iXyespct2 = ideoyes2*yespct
gen iXyes1 = iyes1*yespct
gen iXyes2 = iyes2*yespct

save temp, replace
clear

* Create yes/no votes on each measure
use temp
collapse (sum) rollyesN=rollyes (sum) rollnoN=rollno ///
 (sum) rollyesRN=rollyesR (sum) rollyesDN=rollyesD ///
 (sum) rollnoRN=rollnoR (sum) rollnoDN=rollnoD (mean) majgop, by(propno Chamber)
gen rctot = rollyesN+rollnoN
gen rcmargin = rollyesN-rollnoN
gen rcmarginpct = rcmargin/rctot


merge 1:m propno Chamber using temp

erase temp.dta

gen medH = (sal==3)
gen medM = (sal==2)
gen medL = (sal==1)


*-------------------------------------------------------------------------------
* Table 1. BASICS
/* (remove this line for Table 1)

summarize cong if rollvalid==1
tabstat cong if rollvalid==1, stats(n mean semean min max) col(stat) longstub by(Chamber)
tabstat cong if rollvalid==1, stats(n mean semean min max) col(stat) longstub by(party)

summarize cong if rollvalid==1 & repeal==1
tabstat cong if rollvalid==1 & repeal==1, stats(n mean semean min max) col(stat) longstub by(Chamber)
tabstat cong if rollvalid==1 & repeal==1, stats(n mean semean min max) col(stat) longstub by(party)

summarize cong if rollvalid==1 & repeal==0
tabstat cong if rollvalid==1 & repeal==0, stats(n mean semean min max) col(stat) longstub by(Chamber)
tabstat cong if rollvalid==1 & repeal==0, stats(n mean semean min max) col(stat) longstub by(party)

exit
*/

* Section 2B: Comparison of ideology by party
/*
ttest ideo, by(party)
exit
*/

********************************************************************************



********************************************************************************
* TABLE 2. Congruence comparison
* DISAGREE1 = roll call, DISAGREE2 = referendum, DISAGREE3 = sponsor
/* (Remove this line for Table 2)

drop if rollvalid==0
prtest cong, by(DISAGREE1)
prtest cong, by(DISAGREE2)
prtest cong, by(DISAGREE3)
*
prtest cong if party==-1, by(DISAGREE1)
prtest cong if party==1, by(DISAGREE1)

*
prtest cong if yes50<.55, by(DISAGREE1)
prtest cong if yes50>.55, by(DISAGREE1)
prtest cong if yes50>.60, by(DISAGREE1)
prtest cong if yes50>.70, by(DISAGREE1)
*
prtest cong if ideoabs>.5, by(DISAGREE1)
prtest cong if ideoabs>.75, by(DISAGREE1)
prtest cong if ideoabs>1, by(DISAGREE1)
*
prtest cong if yes50>.55 & ideoabs>.5, by(DISAGREE1)
prtest cong if yes50>.60 & ideoabs>.75, by(DISAGREE1)
prtest cong if yes50>.70 & ideoabs>1, by(DISAGREE1)
*

exit
*/
********************************************************************************


********************************************************************************
* TABLE 3. Regressions of Congruence and DISAGREE
/* (Remove this line for Table 3)

replace cong = cong*100
replace yes50 = yes50*100

reghdfe cong AGREE1 yes50, absorb(ID propchno) cluster(propchno)
reghdfe cong AGREE1 yes50 if repeal==0, absorb(ID propchno) cluster(propchno)
reghdfe cong AGREE1 yes50 if repeal==1, absorb(ID propchno) cluster(propchno)

exit
*/
********************************************************************************



********************************************************************************
* ONLINE APPENDIX TABLE 3 with continuous alignment
* ideo: min = -3.79, max = 2.787
/* (Remove this line for Online Appendix Table B)

gen ideoNORM = ideo
gen districtconserv1 = yespct if issuevalid1==1
replace districtconserv1 = 1-yespct if issuescore1==-1 & issuevalid1==1
gen districtNORM = (districtconserv1-.5)/.5
gen ALIGNcont = ideoNORM*districtNORM

xtset ID

reg ALIGNcont AGREE1

replace cong = cong*100
replace yes50 = yes50*100
summarize cong yespct ALIGNcont AGREE1

reghdfe cong ALIGNcont yes50, absorb(ID propchno) cluster(propchno)
reghdfe cong ALIGNcont yes50 if repeal==0, absorb(ID propchno) cluster(propchno)
reghdfe cong ALIGNcont yes50 if repeal==1, absorb(ID propchno) cluster(propchno)

exit
*/
********************************************************************************

********************************************************************************
* TABLE 4. Estimated Probabilities from Roll call vote regressions (and OA Table C)
/* (Remove this line for Table 4)

replace rollyes = rollyes*100
replace yespct = yespct*100
replace iXyespct1 = iXyespct1*100
replace iXyespct2 = iXyespct2*100
replace iXyes1 = iXyes1*100
replace iXyes2 = iXyes2*100

reghdfe rollyes iyes1 yespct iXyes1, absorb(propchno) cluster(propchno)
lincom _cons + -iyes1 + yespct*40 - iXyes1*40
lincom _cons + -iyes1 + yespct*50 - iXyes1*50
lincom _cons + -iyes1 + yespct*60 - iXyes1*60
lincom _cons + yespct*40
lincom _cons + yespct*50
lincom _cons + yespct*60
lincom _cons + iyes1 + yespct*40 + iXyes1*40
lincom _cons + iyes1 + yespct*50 + iXyes1*50
lincom _cons + iyes1 + yespct*60 + iXyes1*60


reghdfe rollyes iyes1 yespct iXyes1 if repeal==0, absorb(propchno) cluster(propchno)
lincom _cons + -iyes1 + yespct*40 - iXyes1*40
lincom _cons + -iyes1 + yespct*50 - iXyes1*50
lincom _cons + -iyes1 + yespct*60 - iXyes1*60
lincom _cons + yespct*40
lincom _cons + yespct*50
lincom _cons + yespct*60
lincom _cons + iyes1 + yespct*40 + iXyes1*40
lincom _cons + iyes1 + yespct*50 + iXyes1*50
lincom _cons + iyes1 + yespct*60 + iXyes1*60
reghdfe rollyes iyes1 yespct iXyes1 if repeal==1, absorb(propchno) cluster(propchno)

exit
*/
********************************************************************************

********************************************************************************
* TABLE 5. DISTRICT IDEOLOGY VS DISTRICT VOTE
/* (Remove this line for Table 5)

* Legislator & District had same ideology
tabstat AGREElegdist if rollvalid==1, stats(n mean semean min max) col(stat) longstub
tabstat AGREElegdist if rollvalid==1, stats(n mean semean min max) col(stat) longstub by(cong)

* District voted according to its ideology
tabstat AGREEdist1 if rollvalid==1, stats(n mean semean min max) col(stat) longstub
tabstat AGREEdist1 if rollvalid==1, stats(n mean semean min max) col(stat) longstub by(cong)

exit
*/
********************************************************************************



********************************************************************************
* TABLE 6. Congruence Regressions
/* (Remove this line for Table 6)

* ROBUSTNESS: DROP UNCONTESTED INCUMBENTS
*drop if unopposed==1 // add this for OA Table D

replace cong = cong*100
replace yes50 = yes50*100
replace closeness = closeness*100
replace rcmarginpct = rcmarginpct*100

* (1)
reg cong AGREE1 yes50 closeness lasttermfull medH medM rcmarginpct, cluster(propch)

* (2)
reghdfe cong AGREE1 yes50 closeness lasttermfull medH medM rcmarginpct, absorb(ID) cluster(propch ID)

* (3)
reghdfe cong AGREE1 yes50 closeness lasttermfull medH medM rcmarginpct if repeal==0, absorb(ID) cluster(propch ID)

* (4)
reghdfe cong AGREE1 yes50 closeness lasttermfull medH medM rcmarginpct if repeal==1, absorb(ID) cluster(propch ID)

exit
*/
********************************************************************************


